﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace BlimpControlPanel
{
    public partial class MotorControl : UserControl
    {
        public MotorControl()
        {
            InitializeComponent();
        }

        public void SetCommandStatusLabel(bool success)
        {
            if (success)
            {
                lblCmdStatus.BackColor = Color.Green;
                lblCmdStatus.Text = "Command Successful";
            }
            else
            {
                lblCmdStatus.BackColor = Color.Red;
                lblCmdStatus.Text = "Command Failed";
            }
        }

        public void ResetCommandStatusLabel()
        {
            lblCmdStatus.BackColor = btnGoDown.BackColor;
            lblCmdStatus.ForeColor = Color.Black;
            lblCmdStatus.Text      = "Command Status";
        }

        private void btnSendMotorCommands_Click(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(System.Windows.Forms.Button))
            {
                string outString = "";

                switch (((System.Windows.Forms.Button)sender).Name)
                {
                    case "btnMotorsOn":
                        Debug.WriteLine("MOTORS ON");
                        outString = "ON";
                        break;
                    case "btnMotorsOff":
                        Debug.WriteLine("MOTORS OFF");
                        outString = "OFF";
                        break;
                    case "btnTurnLeft":
                        Debug.WriteLine("TURN LEFT");
                        outString = "LEFT";
                        break;
                    case "btnTurnRight":
                        Debug.WriteLine("TURN RIGHT");
                        outString = "RIGHT";
                        break;
                    case "btnGotoWaypoint":
                        Debug.WriteLine("GOTO WAYPOINT");
                        outString = "WAYPOINT";
                        break;
                    case "btnGotoHome":
                        Debug.WriteLine("GOTO WAYPOINT");
                        outString = "HOME";
                        break;
                    case "btnGoDown":
                        Debug.WriteLine("DOWN");
                        outString = "DOWN";
                        break;
                    case "btnGoUp":
                        Debug.WriteLine("UP");
                        outString = "UP";
                        break;
                    default:
                        return;
                }

                if(writeCommand != null)
                    writeCommand(outString);
            }
        }

        // Define a delegate named LogHandler, which will encapsulate
        // any method that takes a string as the parameter and returns no value
        public delegate void WriteCommandHandler(string message);

        // Define an Event based on the above Delegate
        public event WriteCommandHandler writeCommand;
     }
}
